﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;
using ClassLibrary.Utilities;


public partial class Client_UserControl_ucLogin : System.Web.UI.UserControl
{
    TblUserAccountDAO userDAO = new TblUserAccountDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void cmdLogin_Click(object sender, ImageClickEventArgs e)
    {
        bool bFlag = false;
        try
        {
            TblUserAccount userAccount = userDAO.GetUser(txtUsername.Text.Trim(), Encryption.EncryptToString(txtPassword.Text));
            if (userAccount != null)
            {
                {
                    if (userAccount.AccountStatus > 0)
                    {
                        //userAccountDAO.Insert(userAccount, 6);
                        Session[Global.SESSION_LOGGED_USER] = userAccount;
                        bFlag = true;
                    }
                    else
                    {
                        lblMessage.Text = "Account has not been activated.";
                        //lblMessage.Visible = true;
                    }
                }
            }
            else
            {
                lblMessage.Text = "Invalid account.";
                lblMessage.Visible = true;
            }
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
        if (bFlag)
        {
            ScriptManager.RegisterStartupScript(cmdLogin, cmdLogin.GetType(), "ScriptLoginSuccess", "UpdateParentsLogin();", true);
        }
    }
}
